<%--
  Created by IntelliJ IDEA.
  User: 刘帆
  Date: 2023/7/9
  Time: 15:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>商品界面</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <link rel="stylesheet" href="./css/fileinput.min.css">

    <script src="http://code.jquery.com/jquery-3.7.0.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <script src="./js/fileinput.min.js"></script>
    <style>
        /*th,td{ text-align: center}
        .navbar {
            font-size: 25px;
            background-color: #2e317c;
        }*/
        h1{
            position: absolute;/*绝对定位*/
            left: 10%;/*距离游览器左边*/
            top: 10%;/*距离游览器上边*/
        }
    </style>

</head>
<body> <%--style="background-image: url('./images/bg.jpeg')"--%>
<div class="row" style="line-height: 200px">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">购物商城</a>
                </div>
                <div>
                    <!--向左对齐-->
                    <ul class="nav navbar-nav navbar-left">
                        <li class="dropdown">
                            <a href="home2.jsp" class="dropdown-toggle">
                                首页
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="shopping2.jsp" class="dropdown-toggle">
                                商品
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="myorder.jsp" class="dropdown-toggle" >我的订单</a>
                        </li>
                        <li class="dropdown">
                            <a href="Person.jsp" class="dropdown-toggle">
                                个人中心
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="/Test/buyerlogout" class="dropdown-toggle">
                                退出
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="login.html" class="dropdown-toggle">
                                后台登陆
                            </a>
                        </li>

                    </ul>
                    <!--向右对齐-->
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="shopcar.jsp" class="dropdown-toggle">
                                <img  src="./images/GWC.jpg" style="width: 50px; height: 50px;" alt="Logo">
                            </a>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle">
                        <li class="dropdown"><%=session.getAttribute("buyername")%></li>
                        </a>
                        </li>
                        <li><a href="buyerlogin.jsp"><span class="glyphicon glyphicon-user"></span>登录<b class="caret"></b></a></li>

                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="col-md-1"></div>
</div>
<div>
    <!-- 表格部分 开始 -->
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <table class="table table-striped table-bordered table-hover">
               <%-- <h1>我的购物车</h1>--%>
                <thead>
                <tr>
                    <th class="col-md-2">商品号</th>
                    <th class="col-md-2">商品名</th>
                    <th class="col-md-2">商品图片</th>
                    <th class="col-md-2">商品单价</th>
                    <%--                <th class="col-md-2">商品数量</th>--%>
                    <th class="col-md-2">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                </tbody>
            </table>
            <ul class="pagination" style="margin-left: 35%" id="fy">
                <%--<li><a href="#">&laquo;</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li><a href="#">&raquo;</a></li>--%>
            </ul>
        </div>
    </div>
</div>
<br><br>

<input type="button" id="btn2" calss="btn" value="提交订单" style="position: absolute; left: 500px; top: 500px; width: 200px; height: 50px;">



</body>

<script>
    document.getElementById("btn2").onclick = function()
    {
        location.href="pay.jsp";

    }
</script>



<script>






    var pageIndex = 1;//第几页
    var pageSize = 5;//每页几条
    buyerListName(pageIndex, pageSize);
    //根据当前用户查询
    function buyerListName(pageIndex, pageSize) {
        //获取搜索框的内容
        var searchname =<%=session.getAttribute("buyername")%>;
        var obj = {};//定义一个对象
        //获取搜索的名称

        //组装数据
        obj.search = null;
        obj.pageIndex = pageIndex;
        obj.pageSize = pageSize;


        $.ajax({
                url: "/Test/orders?method=getOrdersName",//请求路径
                //data:JSON.stringify(obj),//请求数据
                data: {
                    searchname: searchname,
                    pageIndex: pageIndex,
                    pageSize: pageSize,
                },
                type: "GET",//请求方式
                dataType: "json",//请求数据类型
                contentType: "application/json",//返回数据类型
                success: function (data) {
                    console.log(data);
                    //渲染表格
                    var html = "";
                    var count = data.count;//总条数
                    data = data.data;
                    data.forEach((e, i) => {
                        html += ' <tr>' +
                            '<td>' + i + '</td>' +
                            '<td>' + e.ordersname + '</td>' +
                            '<td><img src="'+e.avatar+'" width="80"></td>'+
                            '<td>' + e.ordersprice + '</td>' +
                            '<td>'+
                            '<button onclick="del('+e.ordersid+')" type="button" class="btn btn-danger btn-xs">删除</button>'
                            +'</td>'+
                            '</tr>'
                    })
                    $("#tb").html(html);


                    //渲染分页
                    var fyhtml='<li><a onclick="buyerList('+(pageIndex-1>0?pageIndex-1:1)+','+pageSize+')" href="#">&laquo;</a></li>';
                    //调用Math.ceil()向上取整  2.1=3  2.5=3
                    var page= Math.ceil(count/pageSize);
                    for(var i=1;i<=page;i++){
                        fyhtml +=' <li><a onclick="buyerList('+i+','+pageSize+')" href="#">'+i+'</a></li>';
                    }
                    fyhtml += ' <li><a onclick="buyerList('+(pageIndex+1>=page?page:(pageIndex+1))+','+pageSize+')" href="#">&raquo;</a></li>';
                    $("#fy").html(fyhtml);
                }
            }
        )
    }


    //删除用户
    function del(ID)
    {


        $.ajax
        (
            {
                url: "/Test/orders?method=deleteOrders",//请求路径
                data: {ordersid:ID},//请求数据
                type: "POST",//请求方式
                //dataType: "json",//请求数据类型
                //contentType: "application/json",//返回数据类型
                success: function (data) {
                    console.log(data);
                    data = JSON.parse(data);//把后台的数据处理为json格式
                    if (data.code == "0000") {
                        alert("删除成功！");
                        buyerListName(1, 5);//刷新列表
                        $("#myModal").modal("hide");//模态框隐藏
                    } else {
                        alert("删除失败！");
                    }
                }
            }
        )
    }


</script>
</html>
